package com.sxkiler.demo.datastruct;

import org.checkerframework.checker.units.qual.A;
//循环队列
public class ArrayQueue {
    private int head;
    private int tail;
    private String[] items;
    private int len;
    private int size;
    public ArrayQueue(int len){
        items = new String[len];
        head = 0;
        tail = 0;
        size = 0;
        this.len = len;
    }
    //这里好像有点问题
    public boolean pushQueue(String str){
        if(size==len)return false;
//        if((tail+1)%len==head)return false;
        items[tail]=str;
        this.tail = (tail+1)%len;
        this.size +=1;
        return true;
    }
    public String popQueue(){
//        if(head==tail)return null;
        if(size==0)return null;
        String item =  items[head];
        this.head = (head+1)%len;
        this.size -=1;
        return item;
    }

    public int getHead() {
        return head;
    }

    public int getTail() {
        return tail;
    }
    public int getSize(){
        return size;
    }

    public static void main(String args[]){
        ArrayQueue queue = new ArrayQueue(10);
        System.out.println(queue.pushQueue("123")+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
//        System.out.println(queue.popQueue()+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
//        System.out.println(queue.popQueue()+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
        System.out.println(queue.pushQueue("123")+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
//        System.out.println(queue.popQueue()+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
        System.out.println(queue.pushQueue("123")+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
        System.out.println(queue.pushQueue("123")+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
        System.out.println(queue.pushQueue("123")+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
        System.out.println(queue.pushQueue("123")+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
        System.out.println(queue.pushQueue("123")+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
        System.out.println(queue.pushQueue("123")+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
        System.out.println(queue.pushQueue("123")+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
        System.out.println(queue.pushQueue("123")+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
        System.out.println(queue.pushQueue("123")+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
        System.out.println(queue.pushQueue("123")+"="+queue.getHead()+","+queue.getTail()+","+queue.getSize());
    }
}
